package cn.itsource.system.service.impl;

import cn.itsource.basic.util.PageList;
import cn.itsource.system.domain.DictionaryType;
import cn.itsource.system.mapper.DictionaryTypeMapper;
import cn.itsource.system.query.DictionaryTypeQuery;
import cn.itsource.system.service.IDictionaryTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class DictionaryTypeServiceImpl implements IDictionaryTypeService {

    @Autowired
    DictionaryTypeMapper dictionaryTypeMapper;

    @Override
    @Transactional
    public void add(DictionaryType dictionaryType) {
        dictionaryTypeMapper.save(dictionaryType);
    }

    @Override
    @Transactional
    public void update(DictionaryType dictionaryType) {
        dictionaryTypeMapper.update(dictionaryType);
    }

    @Override
    @Transactional
    public void remove(Long id) {
        dictionaryTypeMapper.delete(id);
    }

    @Override
    public DictionaryType queryById(Long id) {
        return dictionaryTypeMapper.loadById(id);
    }

    @Override
    public List<DictionaryType> queryAll() {
        return dictionaryTypeMapper.loadAll();
    }

    @Override
    public PageList<DictionaryType> queryPage(DictionaryTypeQuery typeQuery) {
        Integer total = dictionaryTypeMapper.queryCount(typeQuery);
        if (total == 0){
            return new PageList<>();
        }else {
            List<DictionaryType> list = dictionaryTypeMapper.queryData(typeQuery);
            return new PageList<>(total,list);
        }
    }
}
